﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace T5task1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string textBox1 = this.textBox1.Text;
            string textBox2 = this.textBox2.Text;
            //非空验证
            if (textBox1.Equals ("") || textBox2.Equals(""))
            {
                MessageBox.Show("用户名和密码不能为空！");
            }
            else 
            {
                //链接对象
                string connSto = "server=.;database=Admin;Integrated Security=true";
                //创建连接对象
                SqlConnection conn = new SqlConnection(connSto);
                //打开数据库连接
                conn.Open();
                string sql = "select*from Lin where Name='" + textBox1 + "'and Password='" + textBox2 + "'";
                SqlCommand cmd = new SqlCommand(sql,conn);
                cmd.CommandType = CommandType.Text;
                SqlDataReader sdr;
                sdr = cmd.ExecuteReader();
                if (sdr.Read())
                {
                    //登录成功
                    MessageBox.Show("登录成功","提示信息");
                    conn.Close();
                }
                else
                {
                    //登录失败
                    MessageBox.Show("登录失败","提示信息");
                    return;
                }
                
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
